import { Request as request } from '@/utils/request'
import { PageParam } from '@/config/common'

export const getRoles = (pageParams: PageParam, data: any) => {
  return request({
    url: '/sys-role/page-list',
    method: 'post',
    params: pageParams,
    data
  })
}

export const getTotalRoles = () => {
  return request({
    url: '/sys-role/total-list',
    method: 'post'
  })
}

export const getRoleInfo = (id: string) => {
  return request({
    url: `/sys-role/info/${id}`,
    method: 'get'
  })
}

export const saveRole = (data: any) => {
  return request({
    url: '/sys-role/save',
    method: 'post',
    data
  })
}

export const removeRole = (id: string) => {
  return request({
    url: `/sys-role/remove/${id}`,
    method: 'delete'
  })
}

export const saveUserRole = (userIds: string[], roleId: string) => {
  return request({
    url: '/sys-role/save-users',
    method: 'post',
    params: {
      userIds: userIds.join(),
      roleId
    }
  })
}

export const deleteUserRole = (userId: string, roleId: string) => {
  return request({
    url: '/sys-role/delete-user-role',
    method: 'post',
    params: {
      userId,
      roleId
    }
  })
}

/**
 * 保存角色权限
 * @returns {*}
 */
export const saveRolePermission = (roleId: string, permissionIds: string[]) => {
  return request({
    url: `/sys-role/save-role-permission/${roleId}`,
    method: 'post',
    params: {
      permissionIds: permissionIds.join(',')
    }
  })
}
